<template>
  <div class="home-wrap">
    <div class="page-header-index-wide page-header-wrapper-grid-content-main">
      <a-row :gutter="0">
        <a-col :md="24" :lg="24">
          <a-card :bordered="false">
            <div class="info_box">
              <div class="info_l">
                <div class="info_item">
                  <span class="info_label">账号: </span>
                  <span class="info_value">{{ info.username }}</span>
                </div>
                <div class="info_item">
                  <span class="info_label">姓名: </span>
                  <span class="info_value">{{ info.realname }}</span>
                </div>
                <div class="info_item">
                  <span class="info_label">手机号: </span>
                  <span class="info_value">{{ info.phone }}</span>
                </div>
                <div class="info_item">
                  <span class="info_label">部门: </span>
                  <span class="info_value">{{ info.departNames }}</span>
                </div>
                <div class="info_item">
                  <span class="info_label">角色: </span>
                  <span class="info_value">{{ info.roleNames }}</span>
                </div>
                <a-button  @click="changePassword">修改密码</a-button>
              </div>
              <div class="info_r">
                <div class="account-center-avatarHolder">
                  <div class="avatar" v-if="info.avatar">
                    <img :src="getAvatar(info.avatar)" />
                  </div>
                  <div class="avatar" v-else>
                    <img src="~@/assets/img/defaltAvatar.png" />
                  </div>
                  <j-upload text="更换头像" @change="getFileList"></j-upload>
                </div>
              </div>
            </div>
          </a-card>
        </a-col>
      </a-row>
    </div>
    <password-modal ref="modalForm" @ok="modalFormOk"></password-modal>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getFileAccessHttpUrl } from '@/api/manage'
import JUpload from '@/components/jeecg/JUploadAvatar'
import PasswordModal from './modules/PasswordModal'
import { getAction } from '../../../api/manage'
import {fileBaseUrl} from '@/utils/request'
export default {
  components: {
    JUpload,
    PasswordModal
  },
  data() {
    return {
      fileList: [],
      info: []
    }
  },
  mounted() {
    this.getInfo()
  },
  computed: {
  },
  methods: {
    changePassword() {
      this.$refs.modalForm.add(this.info)
    },
    getAvatar(url) {
      return fileBaseUrl + '/jksaas-mgt/mgt/sys/common/static2/' + url
    },
    // 上传文件回调
    getFileList(file) {
      console.log('上传的文件返回了什么：', file)
      getAction(`/sys/user/addUserImage?avatar=${file}`).then(res => {
        if (res.success) {
          this.$antdMessage.success(res.message)
          this.getInfo(true)
        } else {
          this.$antdMessage.error(res.message)
        }
        // this.info = res.result
      })
    },
    ...mapGetters(['nickname', 'avatar']),
    getInfo(e) {
      getAction('/sys/user/getUserPersonInfo').then(res => {
        this.info = res.result
        if (e) {
          let userInfo = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
          userInfo.value.avatar = this.info.avatar
          localStorage.setItem('pro__Login_Userinfo', JSON.stringify(userInfo))
          setTimeout(() => {
            this.$router.go(0)
          }, 1000)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.page-header-wrapper-grid-content-main {
  width: 100%;
  height: 100%;
  min-height: 100%;
  transition: 0.3s;

  .account-center-avatarHolder {
    text-align: center;
    margin-bottom: 24px;

    & > .avatar {
      margin: 0 auto;
      width: 104px;
      height: 104px;
      margin-bottom: 20px;
      border-radius: 50%;
      overflow: hidden;
      img {
        height: 100%;
        width: 100%;
      }
    }

    .username {
      color: rgba(0, 0, 0, 0.85);
      font-size: 20px;
      line-height: 28px;
      font-weight: 500;
      margin-bottom: 4px;
    }
  }

  .account-center-detail {
    p {
      margin-bottom: 8px;
      padding-left: 26px;
      position: relative;
    }

    i {
      position: absolute;
      height: 14px;
      width: 14px;
      left: 0;
      top: 4px;
      background: url(https://gw.alipayobjects.com/zos/rmsportal/pBjWzVAHnOOtAUvZmZfy.svg);
    }

    .title {
      background-position: 0 0;
    }
    .group {
      background-position: 0 -22px;
    }
    .address {
      background-position: 0 -44px;
    }
  }

  .account-center-tags {
    .ant-tag {
      margin-bottom: 8px;
    }
  }

  .account-center-team {
    .members {
      a {
        display: block;
        margin: 12px 0;
        line-height: 24px;
        height: 24px;
        .member {
          font-size: 14px;
          color: rgba(0, 0, 0, 0.65);
          line-height: 24px;
          max-width: 100px;
          vertical-align: top;
          margin-left: 12px;
          transition: all 0.3s;
          display: inline-block;
        }
        &:hover {
          span {
            color: #1890ff;
          }
        }
      }
    }
  }

  .tagsTitle,
  .teamTitle {
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    margin-bottom: 12px;
  }
}
.info_box {
  padding: 50px 300px;
  display: flex;
  justify-content: space-between;
  height: calc(100vh - 180px);
  .info_l {
    .info_item {
      margin-bottom: 40px;
    }
  }
  .info_r {
  }
}
</style>
